<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Minitest::Benchmark - minitest: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Test
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-bench_exp">::bench_exp</a>
    <li ><a href="#method-c-bench_linear">::bench_linear</a>
    <li ><a href="#method-c-bench_range">::bench_range</a>
    <li ><a href="#method-i-assert_performance">#assert_performance</a>
    <li ><a href="#method-i-assert_performance_constant">#assert_performance_constant</a>
    <li ><a href="#method-i-assert_performance_exponential">#assert_performance_exponential</a>
    <li ><a href="#method-i-assert_performance_linear">#assert_performance_linear</a>
    <li ><a href="#method-i-assert_performance_logarithmic">#assert_performance_logarithmic</a>
    <li ><a href="#method-i-assert_performance_power">#assert_performance_power</a>
    <li ><a href="#method-i-fit_error">#fit_error</a>
    <li ><a href="#method-i-fit_exponential">#fit_exponential</a>
    <li ><a href="#method-i-fit_linear">#fit_linear</a>
    <li ><a href="#method-i-fit_logarithmic">#fit_logarithmic</a>
    <li ><a href="#method-i-fit_power">#fit_power</a>
    <li ><a href="#method-i-sigma">#sigma</a>
    <li ><a href="#method-i-validation_for_fit">#validation_for_fit</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Minitest::Benchmark">
    <h1 id="class-Minitest::Benchmark" class="class">
      class Minitest::Benchmark
    </h1>

    <section class="description">
    
<p>Subclass <a href="Benchmark.html"><code>Benchmark</code></a> to create your own benchmark runs. Methods starting with “bench_” get executed on a per-class.</p>

<p>See <a href="Assertions.html"><code>Minitest::Assertions</code></a></p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-bench_exp" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">bench_exp</span><span
                                class="method-args">(min, max, base = 10)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a set of ranges stepped exponentially from <code>min</code> to <code>max</code> by powers of <code>base</code>. Eg:</p>

<pre class="ruby"><span class="ruby-identifier">bench_exp</span>(<span class="ruby-value">2</span>, <span class="ruby-value">16</span>, <span class="ruby-value">2</span>) <span class="ruby-comment"># =&gt; [2, 4, 8, 16]</span>
</pre>

                              <div class="method-source-code" id="bench_exp-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">bench_exp</span> <span class="ruby-identifier">min</span>, <span class="ruby-identifier">max</span>, <span class="ruby-identifier">base</span> = <span class="ruby-value">10</span>
  <span class="ruby-identifier">min</span> = (<span class="ruby-constant">Math</span>.<span class="ruby-identifier">log10</span>(<span class="ruby-identifier">min</span>) <span class="ruby-operator">/</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log10</span>(<span class="ruby-identifier">base</span>)).<span class="ruby-identifier">to_i</span>
  <span class="ruby-identifier">max</span> = (<span class="ruby-constant">Math</span>.<span class="ruby-identifier">log10</span>(<span class="ruby-identifier">max</span>) <span class="ruby-operator">/</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log10</span>(<span class="ruby-identifier">base</span>)).<span class="ruby-identifier">to_i</span>

  (<span class="ruby-identifier">min</span><span class="ruby-operator">..</span><span class="ruby-identifier">max</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">base</span> <span class="ruby-operator">**</span> <span class="ruby-identifier">m</span> }.<span class="ruby-identifier">to_a</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-bench_linear" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">bench_linear</span><span
                                class="method-args">(min, max, step = 10)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a set of ranges stepped linearly from <code>min</code> to <code>max</code> by <code>step</code>. Eg:</p>

<pre class="ruby"><span class="ruby-identifier">bench_linear</span>(<span class="ruby-value">20</span>, <span class="ruby-value">40</span>, <span class="ruby-value">10</span>) <span class="ruby-comment"># =&gt; [20, 30, 40]</span>
</pre>

                              <div class="method-source-code" id="bench_linear-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 48</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">bench_linear</span> <span class="ruby-identifier">min</span>, <span class="ruby-identifier">max</span>, <span class="ruby-identifier">step</span> = <span class="ruby-value">10</span>
  (<span class="ruby-identifier">min</span><span class="ruby-operator">..</span><span class="ruby-identifier">max</span>).<span class="ruby-identifier">step</span>(<span class="ruby-identifier">step</span>).<span class="ruby-identifier">to_a</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">LocalJumpError</span> <span class="ruby-comment"># 1.8.6</span>
  <span class="ruby-identifier">r</span> = []; (<span class="ruby-identifier">min</span><span class="ruby-operator">..</span><span class="ruby-identifier">max</span>).<span class="ruby-identifier">step</span>(<span class="ruby-identifier">step</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">r</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">n</span> }; <span class="ruby-identifier">r</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-bench_range" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">bench_range</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Specifies the ranges used for benchmarking for that class. Defaults to exponential growth from 1 to 10k by powers of 10. Override if you need different ranges for your benchmarks.</p>

<p>See also: <a href="Benchmark.html#method-c-bench_exp"><code>::bench_exp</code></a> and <a href="Benchmark.html#method-c-bench_linear"><code>::bench_linear</code></a>.</p>

                              <div class="method-source-code" id="bench_range-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 61</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">bench_range</span>
  <span class="ruby-identifier">bench_exp</span> <span class="ruby-value">1</span>, <span class="ruby-value">10_000</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-assert_performance" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">assert_performance</span><span
                                class="method-args">(validation, &amp;work)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Runs the given <code>work</code>, gathering the times of each run. Range and times are then passed to a given <code>validation</code> proc. Outputs the benchmark name and times in tab-separated format, making it easy to paste into a spreadsheet for graphing or further analysis.</p>

<p>Ranges are specified by <a href="Benchmark.html#method-c-bench_range"><code>::bench_range</code></a>.</p>

<p>Eg:</p>

<pre>def bench_algorithm
  validation = proc { |x, y| ... }
  assert_performance validation do |n|
    @obj.algorithm(n)
  end
end</pre>

                              <div class="method-source-code" id="assert_performance-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 83</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">assert_performance</span> <span class="ruby-identifier">validation</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
  <span class="ruby-identifier">range</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">bench_range</span>

  <span class="ruby-identifier">io</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">&quot;#{self.name}&quot;</span>

  <span class="ruby-identifier">times</span> = []

  <span class="ruby-identifier">range</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">GC</span>.<span class="ruby-identifier">start</span>
    <span class="ruby-identifier">t0</span> = <span class="ruby-constant">Minitest</span>.<span class="ruby-identifier">clock_time</span>
    <span class="ruby-identifier">instance_exec</span>(<span class="ruby-identifier">x</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>)
    <span class="ruby-identifier">t</span> = <span class="ruby-constant">Minitest</span>.<span class="ruby-identifier">clock_time</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">t0</span>

    <span class="ruby-identifier">io</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">&quot;\t%9.6f&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">t</span>
    <span class="ruby-identifier">times</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">t</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">io</span>.<span class="ruby-identifier">puts</span>

  <span class="ruby-identifier">validation</span>[<span class="ruby-identifier">range</span>, <span class="ruby-identifier">times</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-assert_performance_constant" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">assert_performance_constant</span><span
                                class="method-args">(threshold = 0.99, &amp;work)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Runs the given <code>work</code> and asserts that the times gathered fit to match a constant rate (eg, linear slope == 0) within a given <code>threshold</code>. Note: because we’re testing for a slope of 0, R^2 is not a good determining factor for the fit, so the threshold is applied against the slope itself. As such, you probably want to tighten it from the default.</p>

<p>See <a href="https://www.graphpad.com/guides/prism/8/curve-fitting/reg_intepretingnonlinr2.htm">www.graphpad.com/guides/prism/8/curve-fitting/reg_intepretingnonlinr2.htm</a> for more details.</p>

<p>Fit is calculated by <a href="Benchmark.html#method-i-fit_linear"><code>fit_linear</code></a>.</p>

<p>Ranges are specified by <a href="Benchmark.html#method-c-bench_range"><code>::bench_range</code></a>.</p>

<p>Eg:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">bench_algorithm</span>
  <span class="ruby-identifier">assert_performance_constant</span> <span class="ruby-value">0.9999</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
    <span class="ruby-ivar">@obj</span>.<span class="ruby-identifier">algorithm</span>(<span class="ruby-identifier">n</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

                              <div class="method-source-code" id="assert_performance_constant-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 127</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">assert_performance_constant</span> <span class="ruby-identifier">threshold</span> = <span class="ruby-value">0.99</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
  <span class="ruby-identifier">validation</span> = <span class="ruby-identifier">proc</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">range</span>, <span class="ruby-identifier">times</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">rr</span> = <span class="ruby-identifier">fit_linear</span> <span class="ruby-identifier">range</span>, <span class="ruby-identifier">times</span>
    <span class="ruby-identifier">assert_in_delta</span> <span class="ruby-value">0</span>, <span class="ruby-identifier">b</span>, <span class="ruby-value">1</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">threshold</span>
    [<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">rr</span>]
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">assert_performance</span> <span class="ruby-identifier">validation</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-assert_performance_exponential" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">assert_performance_exponential</span><span
                                class="method-args">(threshold = 0.99, &amp;work)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Runs the given <code>work</code> and asserts that the times gathered fit to match a exponential curve within a given error <code>threshold</code>.</p>

<p>Fit is calculated by <a href="Benchmark.html#method-i-fit_exponential"><code>fit_exponential</code></a>.</p>

<p>Ranges are specified by <a href="Benchmark.html#method-c-bench_range"><code>::bench_range</code></a>.</p>

<p>Eg:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">bench_algorithm</span>
  <span class="ruby-identifier">assert_performance_exponential</span> <span class="ruby-value">0.9999</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
    <span class="ruby-ivar">@obj</span>.<span class="ruby-identifier">algorithm</span>(<span class="ruby-identifier">n</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

                              <div class="method-source-code" id="assert_performance_exponential-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 153</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">assert_performance_exponential</span> <span class="ruby-identifier">threshold</span> = <span class="ruby-value">0.99</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
  <span class="ruby-identifier">assert_performance</span> <span class="ruby-identifier">validation_for_fit</span>(<span class="ruby-value">:exponential</span>, <span class="ruby-identifier">threshold</span>), <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-assert_performance_linear" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">assert_performance_linear</span><span
                                class="method-args">(threshold = 0.99, &amp;work)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Runs the given <code>work</code> and asserts that the times gathered fit to match a straight line within a given error <code>threshold</code>.</p>

<p>Fit is calculated by <a href="Benchmark.html#method-i-fit_linear"><code>fit_linear</code></a>.</p>

<p>Ranges are specified by <a href="Benchmark.html#method-c-bench_range"><code>::bench_range</code></a>.</p>

<p>Eg:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">bench_algorithm</span>
  <span class="ruby-identifier">assert_performance_linear</span> <span class="ruby-value">0.9999</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
    <span class="ruby-ivar">@obj</span>.<span class="ruby-identifier">algorithm</span>(<span class="ruby-identifier">n</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

                              <div class="method-source-code" id="assert_performance_linear-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 193</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">assert_performance_linear</span> <span class="ruby-identifier">threshold</span> = <span class="ruby-value">0.99</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
  <span class="ruby-identifier">assert_performance</span> <span class="ruby-identifier">validation_for_fit</span>(<span class="ruby-value">:linear</span>, <span class="ruby-identifier">threshold</span>), <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-assert_performance_logarithmic" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">assert_performance_logarithmic</span><span
                                class="method-args">(threshold = 0.99, &amp;work)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Runs the given <code>work</code> and asserts that the times gathered fit to match a logarithmic curve within a given error <code>threshold</code>.</p>

<p>Fit is calculated by <a href="Benchmark.html#method-i-fit_logarithmic"><code>fit_logarithmic</code></a>.</p>

<p>Ranges are specified by <a href="Benchmark.html#method-c-bench_range"><code>::bench_range</code></a>.</p>

<p>Eg:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">bench_algorithm</span>
  <span class="ruby-identifier">assert_performance_logarithmic</span> <span class="ruby-value">0.9999</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
    <span class="ruby-ivar">@obj</span>.<span class="ruby-identifier">algorithm</span>(<span class="ruby-identifier">n</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

                              <div class="method-source-code" id="assert_performance_logarithmic-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 173</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">assert_performance_logarithmic</span> <span class="ruby-identifier">threshold</span> = <span class="ruby-value">0.99</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
  <span class="ruby-identifier">assert_performance</span> <span class="ruby-identifier">validation_for_fit</span>(<span class="ruby-value">:logarithmic</span>, <span class="ruby-identifier">threshold</span>), <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-assert_performance_power" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">assert_performance_power</span><span
                                class="method-args">(threshold = 0.99, &amp;work)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Runs the given <code>work</code> and asserts that the times gathered curve fit to match a power curve within a given error <code>threshold</code>.</p>

<p>Fit is calculated by <a href="Benchmark.html#method-i-fit_power"><code>fit_power</code></a>.</p>

<p>Ranges are specified by <a href="Benchmark.html#method-c-bench_range"><code>::bench_range</code></a>.</p>

<p>Eg:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">bench_algorithm</span>
  <span class="ruby-identifier">assert_performance_power</span> <span class="ruby-value">0.9999</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span>
    <span class="ruby-ivar">@obj</span>.<span class="ruby-identifier">algorithm</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

                              <div class="method-source-code" id="assert_performance_power-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 213</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">assert_performance_power</span> <span class="ruby-identifier">threshold</span> = <span class="ruby-value">0.99</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
  <span class="ruby-identifier">assert_performance</span> <span class="ruby-identifier">validation_for_fit</span>(<span class="ruby-value">:power</span>, <span class="ruby-identifier">threshold</span>), <span class="ruby-operator">&amp;</span><span class="ruby-identifier">work</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fit_error" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">fit_error</span><span
                                class="method-args">(xys) { |x| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Takes an array of x/y pairs and calculates the general R^2 value.</p>

<p>See: <a href="https://en.wikipedia.org/wiki/Coefficient_of_determination">en.wikipedia.org/wiki/Coefficient_of_determination</a></p>

                              <div class="method-source-code" id="fit_error-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 222</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fit_error</span> <span class="ruby-identifier">xys</span>
  <span class="ruby-identifier">y_bar</span>  = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-identifier">y</span> } <span class="ruby-operator">/</span> <span class="ruby-identifier">xys</span>.<span class="ruby-identifier">size</span>.<span class="ruby-identifier">to_f</span>
  <span class="ruby-identifier">ss_tot</span> = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">y</span>    <span class="ruby-operator">-</span> <span class="ruby-identifier">y_bar</span>) <span class="ruby-operator">**</span> <span class="ruby-value">2</span> }
  <span class="ruby-identifier">ss_err</span> = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> (<span class="ruby-keyword">yield</span>(<span class="ruby-identifier">x</span>) <span class="ruby-operator">-</span> <span class="ruby-identifier">y</span>) <span class="ruby-operator">**</span> <span class="ruby-value">2</span> }

  <span class="ruby-value">1</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">ss_err</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">ss_tot</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fit_exponential" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">fit_exponential</span><span
                                class="method-args">(xs, ys)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>To fit a functional form: y = ae^(bx).</p>

<p>Takes x and y values and returns [a, b, r^2].</p>

<p>See: <a href="https://mathworld.wolfram.com/LeastSquaresFittingExponential.html">mathworld.wolfram.com/LeastSquaresFittingExponential.html</a></p>

                              <div class="method-source-code" id="fit_exponential-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 237</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fit_exponential</span> <span class="ruby-identifier">xs</span>, <span class="ruby-identifier">ys</span>
  <span class="ruby-identifier">n</span>     = <span class="ruby-identifier">xs</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-identifier">xys</span>   = <span class="ruby-identifier">xs</span>.<span class="ruby-identifier">zip</span>(<span class="ruby-identifier">ys</span>)
  <span class="ruby-identifier">sxlny</span> = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">*</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">y</span>) }
  <span class="ruby-identifier">slny</span>  = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">y</span>)     }
  <span class="ruby-identifier">sx2</span>   = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">x</span>           }
  <span class="ruby-identifier">sx</span>    = <span class="ruby-identifier">sigma</span> <span class="ruby-identifier">xs</span>

  <span class="ruby-identifier">c</span> = <span class="ruby-identifier">n</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sx2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">sx</span> <span class="ruby-operator">**</span> <span class="ruby-value">2</span>
  <span class="ruby-identifier">a</span> = (<span class="ruby-identifier">slny</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sx2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">sx</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sxlny</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">c</span>
  <span class="ruby-identifier">b</span> = ( <span class="ruby-identifier">n</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sxlny</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">sx</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">slny</span> ) <span class="ruby-operator">/</span> <span class="ruby-identifier">c</span>

  <span class="ruby-keyword">return</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">exp</span>(<span class="ruby-identifier">a</span>), <span class="ruby-identifier">b</span>, <span class="ruby-identifier">fit_error</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">exp</span>(<span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">x</span>) }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fit_linear" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">fit_linear</span><span
                                class="method-args">(xs, ys)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Fits the functional form: a + bx.</p>

<p>Takes x and y values and returns [a, b, r^2].</p>

<p>See: <a href="https://mathworld.wolfram.com/LeastSquaresFitting.html">mathworld.wolfram.com/LeastSquaresFitting.html</a></p>

                              <div class="method-source-code" id="fit_linear-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 281</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fit_linear</span> <span class="ruby-identifier">xs</span>, <span class="ruby-identifier">ys</span>
  <span class="ruby-identifier">n</span>   = <span class="ruby-identifier">xs</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-identifier">xys</span> = <span class="ruby-identifier">xs</span>.<span class="ruby-identifier">zip</span>(<span class="ruby-identifier">ys</span>)
  <span class="ruby-identifier">sx</span>  = <span class="ruby-identifier">sigma</span> <span class="ruby-identifier">xs</span>
  <span class="ruby-identifier">sy</span>  = <span class="ruby-identifier">sigma</span> <span class="ruby-identifier">ys</span>
  <span class="ruby-identifier">sx2</span> = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xs</span>)  { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span>   <span class="ruby-identifier">x</span> <span class="ruby-operator">**</span> <span class="ruby-value">2</span> }
  <span class="ruby-identifier">sxy</span> = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">y</span>  }

  <span class="ruby-identifier">c</span> = <span class="ruby-identifier">n</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sx2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">sx</span><span class="ruby-operator">**</span><span class="ruby-value">2</span>
  <span class="ruby-identifier">a</span> = (<span class="ruby-identifier">sy</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sx2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">sx</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sxy</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">c</span>
  <span class="ruby-identifier">b</span> = ( <span class="ruby-identifier">n</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sxy</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">sx</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sy</span> ) <span class="ruby-operator">/</span> <span class="ruby-identifier">c</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">fit_error</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">x</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fit_logarithmic" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">fit_logarithmic</span><span
                                class="method-args">(xs, ys)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>To fit a functional form: y = a + b*ln(x).</p>

<p>Takes x and y values and returns [a, b, r^2].</p>

<p>See: <a href="https://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html">mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html</a></p>

                              <div class="method-source-code" id="fit_logarithmic-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 259</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fit_logarithmic</span> <span class="ruby-identifier">xs</span>, <span class="ruby-identifier">ys</span>
  <span class="ruby-identifier">n</span>     = <span class="ruby-identifier">xs</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-identifier">xys</span>   = <span class="ruby-identifier">xs</span>.<span class="ruby-identifier">zip</span>(<span class="ruby-identifier">ys</span>)
  <span class="ruby-identifier">slnx2</span> = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">x</span>) <span class="ruby-operator">**</span> <span class="ruby-value">2</span> }
  <span class="ruby-identifier">slnx</span>  = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">x</span>)      }
  <span class="ruby-identifier">sylnx</span> = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-identifier">y</span> <span class="ruby-operator">*</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">x</span>)  }
  <span class="ruby-identifier">sy</span>    = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-identifier">y</span>                }

  <span class="ruby-identifier">c</span> = <span class="ruby-identifier">n</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">slnx2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">slnx</span> <span class="ruby-operator">**</span> <span class="ruby-value">2</span>
  <span class="ruby-identifier">b</span> = ( <span class="ruby-identifier">n</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">sylnx</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">sy</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">slnx</span> ) <span class="ruby-operator">/</span> <span class="ruby-identifier">c</span>
  <span class="ruby-identifier">a</span> = (<span class="ruby-identifier">sy</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">slnx</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">n</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">fit_error</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">*</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">x</span>) }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fit_power" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">fit_power</span><span
                                class="method-args">(xs, ys)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>To fit a functional form: y = ax^b.</p>

<p>Takes x and y values and returns [a, b, r^2].</p>

<p>See: <a href="https://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html">mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html</a></p>

                              <div class="method-source-code" id="fit_power-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 303</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fit_power</span> <span class="ruby-identifier">xs</span>, <span class="ruby-identifier">ys</span>
  <span class="ruby-identifier">n</span>       = <span class="ruby-identifier">xs</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-identifier">xys</span>     = <span class="ruby-identifier">xs</span>.<span class="ruby-identifier">zip</span>(<span class="ruby-identifier">ys</span>)
  <span class="ruby-identifier">slnxlny</span> = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">x</span>) <span class="ruby-operator">*</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">y</span>) }
  <span class="ruby-identifier">slnx</span>    = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xs</span>)  { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>   <span class="ruby-operator">|</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">x</span>)               }
  <span class="ruby-identifier">slny</span>    = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">ys</span>)  { <span class="ruby-operator">|</span>   <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">y</span>)               }
  <span class="ruby-identifier">slnx2</span>   = <span class="ruby-identifier">sigma</span>(<span class="ruby-identifier">xs</span>)  { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>   <span class="ruby-operator">|</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">x</span>) <span class="ruby-operator">**</span> <span class="ruby-value">2</span>          }

  <span class="ruby-identifier">b</span> = (<span class="ruby-identifier">n</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">slnxlny</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">slnx</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">slny</span>) <span class="ruby-operator">/</span> (<span class="ruby-identifier">n</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">slnx2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">slnx</span> <span class="ruby-operator">**</span> <span class="ruby-value">2</span>)
  <span class="ruby-identifier">a</span> = (<span class="ruby-identifier">slny</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">slnx</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">n</span>

  <span class="ruby-keyword">return</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">exp</span>(<span class="ruby-identifier">a</span>), <span class="ruby-identifier">b</span>, <span class="ruby-identifier">fit_error</span>(<span class="ruby-identifier">xys</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> (<span class="ruby-constant">Math</span>.<span class="ruby-identifier">exp</span>(<span class="ruby-identifier">a</span>) <span class="ruby-operator">*</span> (<span class="ruby-identifier">x</span> <span class="ruby-operator">**</span> <span class="ruby-identifier">b</span>)) }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sigma" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">sigma</span><span
                                class="method-args">(enum, &amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Enumerates over <code>enum</code> mapping <code>block</code> if given, returning the sum of the result. Eg:</p>

<pre class="ruby"><span class="ruby-identifier">sigma</span>([<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>])                <span class="ruby-comment"># =&gt; 1 + 2 + 3 =&gt; 6</span>
<span class="ruby-identifier">sigma</span>([<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>]) { <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">**</span> <span class="ruby-value">2</span> } <span class="ruby-comment"># =&gt; 1 + 4 + 9 =&gt; 14</span>
</pre>

                              <div class="method-source-code" id="sigma-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 324</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sigma</span> <span class="ruby-identifier">enum</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
  <span class="ruby-identifier">enum</span> = <span class="ruby-identifier">enum</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">block</span>
  <span class="ruby-identifier">enum</span>.<span class="ruby-identifier">inject</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">sum</span>, <span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-identifier">sum</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">n</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-validation_for_fit" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">validation_for_fit</span><span
                                class="method-args">(msg, threshold)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a proc that calls the specified fit method and asserts that the error is within a tolerable threshold.</p>

                              <div class="method-source-code" id="validation_for_fit-source">
            <pre><span class="ruby-comment"># File minitest-5.20.0/lib/minitest/benchmark.rb, line 333</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">validation_for_fit</span> <span class="ruby-identifier">msg</span>, <span class="ruby-identifier">threshold</span>
  <span class="ruby-identifier">proc</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">range</span>, <span class="ruby-identifier">times</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">rr</span> = <span class="ruby-identifier">send</span> <span class="ruby-node">&quot;fit_#{msg}&quot;</span>, <span class="ruby-identifier">range</span>, <span class="ruby-identifier">times</span>
    <span class="ruby-identifier">assert_operator</span> <span class="ruby-identifier">rr</span>, <span class="ruby-value">:&gt;=</span>, <span class="ruby-identifier">threshold</span>
    [<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>, <span class="ruby-identifier">rr</span>]
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

